﻿Imports ADOEntityKYC
Imports System.Data
Partial Class Form_KYC2T_02
    Inherits System.Web.UI.Page
    Dim KYCEntity As KYCEntities = New KYCEntities
    Dim ds As DataSet

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Response.AddHeader("Cache-control", "no-store, must-revalidate, private,no-cache")
        Response.AddHeader("Pragma", "no-cache")
        Response.AddHeader("Expires", "0")
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        ds = Session("ds")
        bindingData()
        userPrint()

        'Dim pageKey As RegistryKey = Registry.CurrentUser.OpenSubKey("software\microsoft\internet explorer\pagesetup", True)

        'pageKey.SetValue("footer", "")
        'pageKey.SetValue("header", "")
        ''pageKey.SetValue("margin_left", "")
        ''pageKey.SetValue("margin_top", "")
        'pageKey.Close()

        Response.Write("<script>")
        Response.Write("window.print()")
        Response.Write("</script>")

    End Sub

    Private Sub bindingData()

        Dim CUSTSEQ As Integer = Request.QueryString("CUSTSEQ")
        Dim KYCSEQ As Integer = Request.QueryString("KYCSEQ")
        Dim qryCust As Object
        If CUSTSEQ <> 0 Then

            qryCust = (From cust In KYCEntity.MCUSTOMER
                Join p In KYCEntity.MPREFIX On cust.THPREFIX Equals p.PREFIXCODE
               Join n In KYCEntity.MNATIONALITY On cust.NATIONALITY Equals n.NATIONCODE
               Group Join biz In KYCEntity.MBUSINESS On cust.BIZTYPE1 Equals biz.BIZCODE
               Into a = Group From leftA In a.DefaultIfEmpty
               Group Join incom1 In KYCEntity.MNATIONALITY On cust.INCOMESOURCE1 Equals incom1.NATIONCODE
               Into aa = Group From leftAA In aa.DefaultIfEmpty
               Group Join incom2 In KYCEntity.MNATIONALITY On cust.INCOMESOURCE2 Equals incom2.NATIONCODE
               Into b = Group From leftB In b.DefaultIfEmpty
               Group Join incom3 In KYCEntity.MNATIONALITY On cust.INCOMESOURCE3 Equals incom3.NATIONCODE
               Into c = Group From leftC In c.DefaultIfEmpty
               Where cust.CUSTSEQ = CUSTSEQ
               Select cust, p.PREFIXTH, n.NATIONALITYNAME, incomes1 = leftAA.COUNTYNAME,
               leftA.BIZNAME, incomes2 = leftB.COUNTYNAME, incomes3 = leftC.COUNTYNAME).ToList




            If Not qryCust.Count = 0 Then

                If qryCust(0).cust.THPREFIX = 160 Then
                    lblPrefix1.Text = "X"
                ElseIf qryCust(0).cust.THPREFIX = 161 Then
                    lblPrefix2.Text = "X"
                ElseIf qryCust(0).cust.THPREFIX = 205 Then
                    lblPrefix3.Text = "X"
                    'ElseIf qryCust(0).cust.THPREFIX = 54 Then
                    '    lblPrefix4.Text = "X" 'ยังไม่ครบ
                Else
                    lblPrefix5.Text = "X"
                    lblPrefixOther.Text = qryCust(0).PREFIXTH
                End If

                lblTHName.Text = qryCust(0).cust.THFIRSTNAME

                'lblENName.Text = qryCust(0).cust.ENFIRSTNAME.ToUpper
                If Not qryCust(0).cust.ENFIRSTNAME Is Nothing Then
                    lblENName.Text = qryCust(0).cust.ENFIRSTNAME.ToUpper
                End If

                lblUniqueID.Text = qryCust(0).cust.UNIQUEID

                If qryCust(0).cust.BIZTYPE1 = 99 Then
                    lblBiz.Text = qryCust(0).cust.BIZTYPEOTHER1
                Else
                    lblBiz.Text = qryCust(0).BIZNAME
                End If

                lblNational.Text = convertThai(qryCust(0).NATIONALITYNAME)
                'If qryCust(0).cust.ISANSWERSARALY = 1 Then
                '    Dim tempSalary As Double
                '    tempSalary = qryCust(0).cust.SALARYPERMONTH()
                '    lblSalary.Text = String.Format("{0:n}", tempSalary)

                'Else
                '    lblSalary.Text = "-"
                'End If
                Dim tempSalary As Double
                tempSalary = qryCust(0).cust.SALARYPERMONTH()
                lblSalary.Text = String.Format("{0:n}", tempSalary)

                lblIncome.Text = convertThai(qryCust(0).incomes1)
                If Not qryCust(0).cust.INCOMESOURCE2 Is Nothing Then
                    lblIncome.Text += ", " + convertThai(qryCust(0).incomes2)
                End If
                If Not qryCust(0).cust.INCOMESOURCE3 Is Nothing Then
                    lblIncome.Text += ", " + convertThai(qryCust(0).incomes3)
                End If

                If Not qryCust(0).cust.NGOCHECK1 Is Nothing Then
                    If qryCust(0).cust.NGOCHECK1 = 1 Then
                        lblNPO1.Text = "X"
                    ElseIf qryCust(0).cust.NGOCHECK1 = 2 Then
                        lblNPO2.Text = "X"
                    End If
                End If

                If Not qryCust(0).cust.COMPCHECK1 Is Nothing Then
                    If qryCust(0).cust.COMPCHECK1 = 1 Then
                        lblRegis1.Text = "X"
                    ElseIf qryCust(0).cust.COMPCHECK1 = 2 Then
                        lblRegis2.Text = "X"
                    ElseIf qryCust(0).cust.COMPCHECK1 = 3 Then
                        lblRegis3.Text = "X"
                    End If
                End If

            End If


            lblFormalAddr.Text = qryCust(0).cust.FORMALADDR
            lblFormalPhone.Text = qryCust(0).cust.FORMALPHONE1


            If lblNational.Text = "ไทย" Then
                lblChkNation1.Text = "X"
                lblNational.Text = ""
            Else
                lblChkNation2.Text = "X"

            End If

            If lblIncome.Text = "ไทย" Then
                lblChkIncome1.Text = "X"
                lblIncome.Text = ""
            Else
                lblChkIncome2.Text = "X"
            End If

            If Not qryCust(0).cust.CHECKADDRESS Is Nothing Then

                If qryCust(0).cust.CHECKADDRESS = 22 Or qryCust(0).cust.CHECKADDRESS = 25 Then
                    lblEv1.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 23 Or qryCust(0).cust.CHECKADDRESS = 21 Then
                    lblEv2.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 29 Then
                    lblEv3.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 30 Then
                    lblEv4.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 31 Then
                    lblEv5.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 32 Then
                    lblEv6.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 33 Then
                    lblEv7.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 34 Then
                    lblEv8.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 35 Then
                    lblEv9.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 36 Then
                    lblEv10.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 37 Then
                    lblEv11.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 38 Then
                    lblEv12.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 39 Then
                    lblEv13.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 40 Then
                    lblEv14.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 41 Then
                    lblEv15.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 42 Then
                    lblEv16.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 43 Then
                    lblEv17.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 44 Then
                    lblEv18.Text = "X"
                Else
                    lblEv19.Text = "X"
                End If
            End If
            qryCust = Nothing
        End If

    End Sub

    Private Sub userPrint()

        Dim convertDate As clsDateFormat = New clsDateFormat
        Dim clsSessionMenuRight As clsSessionMenuRight = New clsSessionMenuRight
        clsSessionMenuRight = Session("clsMenuRight")

        lblUserName.Text = clsSessionMenuRight.getEmpFirstName + "&nbsp;&nbsp;" + clsSessionMenuRight.getEmpLastName
        lblPrintDate.Text = convertDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, Now.Date)
        lblUserID.Text = clsSessionMenuRight.getUserName
        lblBranch.Text = clsSessionMenuRight.getBranchName
        convertDate = Nothing
        clsSessionMenuRight = Nothing

    End Sub

    Private Function convertThai(ByVal country As String) As String
        Dim str As String = ""
        If country = "THAI" Or country = "THAILAND" Then
            str = "ไทย"
        Else
            str = country
        End If

        Return str
    End Function


End Class
